package com.jrsoft.bim.dto;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * ${DESCRIPTION}
 *
 * @author Blueeyedboy
 * @create 2019-12-20 10:48 AM
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class R<T> implements Serializable {
	public int code = 0;
	public String msg;
	public T data;

	public static R ok(){
		return R.builder().build();
	}

	public static R ok(String msg){
		return R.builder().msg(msg).build();
	}

	public static R ok(String msg,Object data){
		return R.builder().msg(msg).data(data).build();
	}

	public static R error(String msg){
		return R.builder().code(500).msg(msg).build();
	}

	public static R error(String msg,Object data){
		return R.builder().code(500).msg(msg).data(data).build();
	}

	public static R error(int code,String msg){
		return R.builder().code(code).msg(msg).build();
	}

	public String toJson(){
		return JSON.toJSONString(this);
	}

}
